local TARGET_NAME = "apika"
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
local host = os.host()
local project_dir = os.scriptdir()
print("project_dir: " .. project_dir)

target(TARGET_NAME)
    set_kind("static")
    set_targetdir(LIB_DIR)

    -- 编译前将py文件转化成.c文件
    before_build(function (target)
        -- 执行清理旧文件的命令，并等待其完成
        if host == "linux" then
            os.exec(project_dir .. "/" .. "bash ./on_build.sh")
        elseif host == "windows" then
            os.exec(project_dir .. "/" .. "on_build.bat")
        else
            -- 其他平台的处理
            print("Unsupported platform: " .. host)
        end
    end)


    -- 源文件
    add_files("PikaPython/pikascript-api/*.c",{public = true})
    add_files("PikaPython/pikascript-core/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/PikaStdLib/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/PikaStdDevice/*.c",{public = true})  
    add_files("PikaPython/pikascript-lib/network/*.c",{public = true})  
    add_files("PikaPython/pikascript-lib/socket/*.c",{public = true})  
    add_files("PikaPython/pikascript-lib/time/*.c",{public = true}) 
    add_files("PikaPython/pikascript-lib/air780e/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/pika_hal_ex/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/_thread/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/threading/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/collections/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/queue/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/utime/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/os/*.c",{public = true})
    -- add_files("PikaPython/pikascript-lib/pika_libc/*.c",{public = true}) -- 没用就不要加
    add_files("PikaPython/pikascript-lib/StdDevice/*.c",{public = true})
    add_files("PikaPython/pikascript-lib/StdMobile/*.c",{public = true})
    -- add_files("PikaPython/pikascript-lib/iconv/*.c",{public = true}) --与合宙CSDK重复
    
    -- 头文件
    add_includedirs("PikaPython/pikascript-api",{public = true})
    add_includedirs("PikaPython/pikascript-core",{public = true})
    add_includedirs("PikaPython/pikascript-lib/PikaStdLib",{public = true})
    add_includedirs("PikaPython/pikascript-lib/PikaStdDevice",{public = true})
    add_includedirs("PikaPython/pikascript-lib/socket",{public = true})
    add_includedirs("PikaPython/pikascript-lib/network",{public = true})
    add_includedirs("PikaPython/pikascript-lib/air780e",{public = true})
    add_includedirs("PikaPython/pikascript-lib/threading",{public = true})
    add_includedirs("PikaPython/pikascript-lib/pika_hal_ex",{public = true})
    add_includedirs("PikaPython/pikascript-lib/os",{public = true})
    add_includedirs("PikaPython/pikascript-lib/StdDevice",{public = true})
    -- add_includedirs("PikaPython/pikascript-lib/iconv",{public = true}) --与合宙CSDK重复

    -- ============== 合宙CSDK的代码和头文件 ==============

    -- iconv
    includes(SDK_TOP .. "/thirdparty/iconv")
    add_deps("iconv")
    -- add_includedirs(SDK_TOP .. "../LuatOS/components/iconv")
    -- add_files(SDK_TOP.."../LuatOS/components/iconv/*.c|luat_lib_iconv.c",{public = true})

    -- add_includedirs(SDK_TOP .. "/thirdparty/iconv")
    -- add_files(SDK_TOP.."/thirdparty/iconv/*.c",{public = true})
    -- sfud与文件系统
    add_includedirs(SDK_TOP .. "/thirdparty/sfud",{public = true})
	add_includedirs(SDK_TOP .. "/thirdparty/vfs",{public = true})
    add_files(SDK_TOP.."/thirdparty/sfud/*.c",{public = true})
	add_files(SDK_TOP.."/thirdparty/vfs/*.c|luat_fs_fatfs.c",{public = true})

    -- 其他文件
    add_includedirs("./inc",{public = true})
    add_files("./src/*.c",{public = true})

    -- add_cflags("-DPIKA_HAL_CIRCULAR_QUEUE_MUTEX_ENABLE")
    -- add_cflags("-DPIKA_FREERTOS_ENABLE")
    -- add_cflags("-DPIKA_LWIP_ENABLE")
    add_cflags("-DPIKA_CONFIG_ENABLE=1")
    --路径可以随便写,可以加任意路径的代码,下面代码等效上方代码
    -- add_includedirs(SDK_TOP .. "project/" .. TARGET_NAME .. "/inc",{public = true})
    -- add_files(SDK_TOP .. "project/" .. TARGET_NAME .. "/src/*.c",{public = true})

    --可以继续增加add_includedirs和add_files
    --自动链接
    LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME .. " "
    --甚至可以加入自己的库
target_end()

-- add_includedirs(SDK_TOP .. "/thirdparty/sfud",{public = true})
-- add_files(SDK_TOP.."/thirdparty/sfud/*.c",{public = true})